import { Component, OnInit } from '@angular/core'
import { JsonApiService } from 'app/core/api/json-api.service' //http请求配置引入
import { Router, ActivatedRoute } from '@angular/router' //路由引入
import { config } from '../../shared/smartadmin.config'
import { stat } from 'fs'
import { DatePickerModule } from '../../shared/date-picker/date-picker.module'

declare var $: any
declare var echarts: any
declare var Viewer: any
@Component({
  selector: 'sa-billing-details',
  templateUrl: './billing-details.component.html',
  styleUrls: ['./billing-details.component.css']
})
export class BillingDetailsComponent implements OnInit {
  tableData: any = [] //table数据
  opeartionParam: any = {
    carArray: [], // 去要结算的车辆列表
    carListImg: '', // 清单图片路径
    accountingDate: '', // 到账时间(yyyy-MM-dd)
    costType: 1, // 费用类型（1.服务费；2.对接费）
    financialId: '', // 资金明细id
    companyId: '', // 公司id
    companyName: '', // 公司名称
    costPrice: 0, // 账单总金额
    arrivalAmount: 0 // 到账金额
  } // 添加或编辑参数
  validatorOptions: any = {} // 验证参数
  fileList: File = null
  imgFileTitle: string = '点击上传'
  concatCompanyParam: any = {
    companyId: ''
  } // 对接厂区参数
  projectParams: any = {
    data: JSON.stringify({
      searchKey: ''
    })
  } // 项目名称参数

  carSelectedTableData: any = [] // 车辆列表
  carAllChecked: boolean = false // 车辆全选按钮
  totalCount: number = 0
  picUrl = '' // 查看图片url
  nowPage: number = 1
  pageSize: number = 10
  status: string = '1' //到账状态 0未到账 1 已到账
  billType: string = '0' //账单类型 1服务费 2 对接费
  accountId: string = '' //账户id
  accountName: string = '' // 账户名称
  companyId: string = '' //公司ID
  companyName: string = '' // 公司名称
  factoryId: string = '' //厂区名称ID
  factoryName: string = '' //厂区名称
  startTime: any = '' // 开始时间
  endTime: any = '' // 结束时间
  carNumber: string = ''
  dataSort: string = '1'
  sortBy: string = '0'
  sortType: string = '1'
  quantityType: string = ''
  userName: string = '' //上传人
  dataSource: any = ['车载平台导入', '小程序']
  constructor(private jsonApiService: JsonApiService, private router: Router, private activatedRoute: ActivatedRoute) {
    activatedRoute.queryParams.subscribe(queryParams => {
      let data: any = common.getCookie('jumpTo/system/billing-details')
      common.clearCookie('jumpTo/system/billing-details')
      data = data ? JSON.parse(data) : {}
      this.companyId = data.companyId || ''
      this.companyName = data.companyName || ''
      this.factoryId = data.factoryId || ''
      this.factoryName = data.factoryName || ''
      this.status = data.status || '1'
      this.billType = data.billType || '0'
      this.startTime = data.startTime || ''
      this.endTime = data.endTime || ''
      if (data.companyId) {
        this.initFactorySelect(data.companyId)
      }
      this.initDate()
    })
  }
  ngOnInit() {
    this.initCompantSelect()
    this.initCompantSelect2()
    this.load()
  }
  ngOnDestroy() {
    document.onclick = null
  }
  // 添加
  addData(modal) {
    let that = this
    const year = new Date().getFullYear()
    let month = new Date().getMonth() + 1
    let day = new Date().getDate()
    const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
    System.import('assets/js/datepicker/js/bootstrap-datetimepicker.min.js').then(() => {
      System.import('assets/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js').then(() => {
        $('#startInstallTime')
          .datetimepicker({
            //时间插件
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            autoclose: true,
            initialDate: new Date(),
            minView: 'month'
          })
          .on('changeDate', function (e) {
            var date = e.date
            const year = new Date(date).getFullYear()
            let month = new Date(date).getMonth() + 1
            let day = new Date(date).getDate()
            const time = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
            that.opeartionParam.accountingDate = time
            that.initWaterOrderSelected(that.opeartionParam.companyId, time)
          })
      })
    })
    this.opeartionParam = {
      carArray: [], // 去要结算的车辆列表
      carListImg: '', // 清单图片路径
      accountingDate: date, // 到账时间(yyyy-MM-dd)
      costType: 1, // 费用类型（1.服务费；2.对接费）
      financialId: '', // 资金明细id
      companyId: '', // 公司id
      companyName: '', // 公司名称
      costPrice: 0, // 账单总金额
      arrivalAmount: 0 // 到账金额
    }
    this.carAllChecked = false
    this.del_companySelect2()
    $('#waterOrderSelect').val()
    $('#waterOrderSelect').html()
    this.carSelectedTableData = []
    modal.show()
  }

  //表格搜索
  table_search() {
    this.load()
  }
  //刷新
  refresh() {
    this.load()
  }

  tabChange(type) {
    this.status = type
    this.load()
  }

  //初始化加载list数据
  load() {
    let tableSearch = {
      nowPage: this.nowPage,
      pageSize: this.pageSize,
      parameters: {
        status: this.status, //到账状态 0未到账 1 已到账
        billType: this.billType === '0' ? '' : this.billType, //账单类型 1服务费 2 对接飞
        accountId: this.accountId, //账户名称
        companyId: this.companyId, //公司名称
        factoryId: this.factoryId, //厂区名称名称
        carNumber: this.carNumber,
        starTime: this.startTime,
        endTime: this.endTime
      }
    }
    let reqdata = 'gridPager=' + JSON.stringify(tableSearch)
    this.jsonApiService.http('CorporateBillingDetails/page.html', reqdata).subscribe(data => {
      if (data.success) {
        var result = data.data.content
        // 遍历处理子节点
        this.tlist = []
        this.totalCount = data.data.totalElements
        this.initTableData(result)
        for (let item of this.tlist) {
          item.installedRatio = item.expectedNum ? ((item.totalNum * 100) / item.expectedNum).toFixed(2) + '%' : ''
          item.alertFlag = false
          if (item.fieldEquipment < 5) {
            item.alertFlag = true
          }
          if (item.peopleNumber) {
            if (item.installedNum / item.peopleNumber < 3) {
              item.alertFlag = true
            }
          }
          if (!item.childNode || item.childNode.length == 0) {
            item.canEdit = true
          } else {
            item.canEdit = false
          }
        }
        this.tableData = this.tlist
      }
    })
  }
  // 标记等级的
  level = 0
  // 最后遍历形成的平级数组
  tlist = []
  // 父级的id
  parentId: number = 0
  // 递归处理表单数据
  initTableData(result) {
    for (let index = 0; index < result.length; index++) {
      const item = result[index]
      item.noShow = false
      this.tlist.push(item)
      if (item.isTop) {
        this.level = 0
        item.parentId = 0
      } else {
        item.parentId = this.parentId
      }
      item.level = this.level
      // 这里是个数组
      if (item.childNode && item.childNode.length > 0) {
        this.parentId = item.id
        item.isShowChild = true
        this.level += 1
        this.initTableData(item.childNode)
      }
    }
  }

  specifyId = {
    picker1: 'datetimepicker3',
    picker2: 'datetimepicker4'
  }

  // 时间选择回调
  dateSelect(time) {
    this.startTime = time.startTime
    this.endTime = time.endTime
  }

  // 初始化1天的时间
  initDate() {
    this.specifyTime = {
      startTime: this.startTime,
      endTime: this.endTime
    }
  }
  specifyTime: any

  // 删除
  delRow(row) {
    this.jsonApiService
      .confirm_message('本次删除将会把同一个流水单号关联的车辆,重新改为未到账,确认要删除?')
      .then(() => {
        let reqdata = 'id=' + row.id
        this.jsonApiService.http('CorporateBillingDetails/deleteById.html', reqdata).subscribe(data => {
          this.jsonApiService.message(data.message)
          if (data.success) {
            this.load()
          }
        })
      })
  }

  // 删除车辆选取单项
  deleteSelectCar(id, costPrice) {
    this.opeartionParam.carArray = this.opeartionParam.carArray.filter(item => {
      return item.id !== id
    })
    this.carSelectedTableData = this.carSelectedTableData.map(item => {
      if (item.detailMsg.id === id) {
        item.isChecked = false
      }
      return item
    })
    this.carAllChecked = false
    const finalCostPrice: number = this.opeartionParam.costPrice - costPrice
    this.opeartionParam.costPrice = finalCostPrice.toFixed(2)
  }

  // 显示车辆选相框
  showCarTree(modal) {
    modal.show()
  }

  //图片放大
  isViewer: Boolean = false
  viewer: any
  // 上传清单图片
  multifileChange(files: FileList) {
    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }

    var that = this
    let multfileList = files

    var reqdata = new FormData()
    reqdata.append('describe', '流水单图片')
    reqdata.append('businessType', '1')
    // reqdata.append('deviceId', this.page.deviceId);
    reqdata.append('type', '2') //type 1获取相对路径  2获取绝对路径

    for (var i = 0; i < multfileList.length; i++) {
      this.fileList = multfileList[i]
      const isJPG =
        this.fileList.type === 'image/jpeg' || this.fileList.type === 'image/jpg' || this.fileList.type === 'image/png'
      if (!isJPG) {
        this.jsonApiService.message('上传图片只能是 png, jpg, jpeg 格式!')
        return
      }

      reqdata.append('files', multfileList[i])
    }

    that.jsonApiService.form_http('fileUpload/upload.html', reqdata).subscribe(data => {
      if (data.success) {
        if (data.data.length > 1) {
          this.jsonApiService.message('上传图片只能是上传一张')
        } else {
          this.opeartionParam.carListImg = data.data[0]
        }
        // for (var i = 0; i < data.data.length; i++) {
        // 	that.imageInfoList.push(data.data[i]);
        // }
      }
    })

    for (let k = 0; k < $('.up').length; k++) {
      $('.up')[k].value = null
    }
  }

  //删除
  deleteImg() {
    this.opeartionParam.carListImg = ''

    if (this.isViewer && $('.viewer-container').length > 0) {
      this.viewer.destroy()
    }
  }

  // 编辑表单数据
  projectDailyFrom: any = {}
  // 编辑
  editRow(modal, row) {
    modal.show()
    // for (let key in this.projectDailyFrom) {
    //   this.projectDailyFrom[key] = row[key];
    // }
    this.opeartionParam = Object.assign(this.opeartionParam, row)
  }
  // 编辑取消
  projectDailyCancel() {
    $('#projectDailyModal').modal('hide')
  }
  // 单项编辑
  editItemPage(title, key, row) {}
  // 单项编辑取消
  itemModalClose() {
    $('#itemModal').modal('hide')
  }
  // 单项数据提交
  itemModalSubmit() {}

  // 车牌选择
  carNoSelected(data) {
    console.log(data, 'ddxx')
  }

  //select2 格式回调函数
  formatRepo(state) {
    if (!state.id) {
      return state.text
    }
    var $state = $('<span><i class="fa fa-user green"></i>&nbsp;&nbsp;' + state.text + '</span>')
    return $state
  }

  //拉取车辆api数据
  getSelectedCarList(companyId, billType) {
    var that = this
    that.jsonApiService
      .http_obj('CorporAccount/carTree.html', {
        companyId,
        billType
      })
      .subscribe(data => {
        if (data.success) {
          that.carSelectedTableData = data.data.filter(item => {
            return item.detailMsg
          })
        }
      })
  }

  // 改变服务费类型
  costTypeChange() {
    this.opeartionParam.companyId &&
      this.getSelectedCarList(this.opeartionParam.companyId, this.opeartionParam.costType)
    this.opeartionParam = Object.assign(this.opeartionParam, {
      carArray: [], // 去要结算的车辆列表
      financialId: '', // 资金明细id
      costPrice: 0 // 账单总金额
    })
  }

  // 初始化selected
  initSelected(selectdata, id, callback = null) {
    var that = this
    System.import('script-loader!select2/dist/js/select2.min.js').then(() => {
      System.import('assets/js/select2-zh-CN.js').then(() => {
        $(id).html('')
        $(id)
          .select2({
            language: 'zh-CN',
            placeholder: '请选择',
            allowClear: true,
            data: selectdata, //为Select添加数据
            templateResult: this.formatRepo
          })
          .on('select2:select', function (e) {
            var data = e.params.data
            callback && callback(e.params.data)
          })
        if (id === '#companySelect') {
          var option = new Option(that.companyName, that.companyId, true, true)
          $('#companySelect').append(option)
        } else if (id === '#factorySelected') {
          var option = new Option(that.factoryName, that.factoryId, true, true)
          $('#factorySelected').append(option)
        } else {
          var option = new Option('', '', true, true)
          $(id).append(option)
        }
      })
    })
  }

  // 关闭添加或编辑弹窗
  closeRenewalModal(modal) {
    modal.hide()
  }

  // 提交
  submitModal(modal) {
    if (this.opeartionParam.carArray.length < 1) {
      this.jsonApiService.message('请选择车辆')
      return
    }

    if (!this.opeartionParam.carListImg) {
      this.jsonApiService.message('请上传清单图片')
      return
    }

    if (!this.opeartionParam.companyId) {
      this.jsonApiService.message('请选择项目')
      return
    }

    this.jsonApiService
      .http_obj('CorporateBillingDetails/addBillDetails.html', {
        data: JSON.stringify(this.opeartionParam)
      })
      .subscribe(data => {
        this.jsonApiService.message(data.message)
        if (data.success) {
          this.load()
          modal.hide()
          this.opeartionParam = {
            carArray: [], // 去要结算的车辆列表
            carListImg: '', // 清单图片路径
            accountingDate: '', // 到账时间(yyyy-MM-dd)
            costType: 1, // 费用类型（1.服务费；2.对接费）
            financialId: '', // 资金明细id
            companyId: '', // 公司id
            companyName: '', // 公司名称
            costPrice: 0, // 账单总金额
            arrivalAmount: 0 // 到账金额
          }
        }
      })
  }

  // 取消车辆选择
  cancelSubmitCar(modal) {
    modal.hide()
  }

  // 确认选择车辆选择
  submitCarCheck() {}

  // 提交新增结算明细 所需要的车辆数据
  redirectCommitCarData(data) {
    return {
      id: data.detailMsg.id, // 账单明细的Id
      carNumber: data.detailMsg.carNumber, // 车牌号
      deviceId: data.detailMsg.deviceId, // 设备编码
      costPrice: data.detailMsg.billAmount, // 账单金额
      factoryId: data.detailMsg.companyId, // 厂区id
      factoryName: data.detailMsg.companyName // 厂区名称
    }
  }

  // 选择所有车辆
  carAllSelected() {
    let carArray = []
    let costPrice = 0
    this.carAllChecked = !this.carAllChecked
    for (let item of this.carSelectedTableData) {
      if (this.carAllChecked === true) {
        item.isChecked = true
        carArray.push(this.redirectCommitCarData(item))
        costPrice += item.detailMsg.billAmount || 0
      } else {
        item.isChecked = false
      }
    }
    this.opeartionParam.carArray = carArray
    this.opeartionParam.costPrice = costPrice
  }

  // 单选车辆
  carRowSelected(data) {
    let allSelected = true
    const nData = JSON.parse(JSON.stringify(data))
    this.carSelectedTableData = this.carSelectedTableData.map(item => {
      if (nData.detailMsg.id === item.detailMsg.id && nData.isChecked === true) {
        // 如果是已选中 并且是此项
        item.isChecked = false
      } else if (nData.detailMsg.id === item.detailMsg.id && !nData.detailMsg.isChecked) {
        item.isChecked = true
      }
      if (!item.isChecked) {
        allSelected = item.isChecked
      }

      return item
    })

    this.carAllChecked = allSelected

    if (nData.isChecked === true) {
      this.opeartionParam.carArray = this.opeartionParam.carArray.filter(item => {
        return item.id !== nData.detailMsg.id
      })
      const costPrice = Number(this.opeartionParam.costPrice) - (nData.detailMsg.billAmount || 0)
      this.opeartionParam.costPrice = costPrice.toFixed(2)
    } else {
      this.opeartionParam.carArray.push(this.redirectCommitCarData(nData))
      const costPrice = Number(this.opeartionParam.costPrice) + (nData.detailMsg.billAmount || 0)
      this.opeartionParam.costPrice = costPrice.toFixed(2)
    }
  }

  imgList: any = []
  imgLocalList: any = []
  isViewer2: boolean = false
  viewer2: any = null
  // 查看大图
  lookPic(carListImg, modal) {
    this.imgList = []
    this.imgLocalList = []
    if (carListImg && carListImg.indexOf(',') > 1) {
      this.imgList = carListImg.split(',')
    } else {
      this.imgList.push(carListImg)
    }
    // this.imgList.push('https://t7.baidu.com/it/u=852388090,130270862&fm=193&f=GIF')
    let localImg
    for (var i = 0; i < this.imgList.length; i++) {
      if (this.imgList[i].indexOf('http') == -1) {
        if (this.imgList[i][0] == '/') {
          localImg = config.BaseURL + this.imgList[i].substr(1)
        } else {
          localImg = config.BaseURL + this.imgList[i]
        }
      } else {
        localImg = this.imgList[i]
      }
      this.imgLocalList.push(localImg)
    }
    modal.show()

    if (this.isViewer2 && $('.viewer-container').length > 0) {
      this.viewer2.destroy()
    }
  }

  //图片放大
  bigimg(type, row) {
    if (this.isViewer2 && $('.viewer-container').length > 0) {
      this.viewer2.destroy()
    }
    if (this.isViewer2 && $('.viewer-container').length > 0) {
      this.viewer2.destroy()
      System.import('assets/js/viewer/viewer.js').then(() => {
        System.import('assets/js/viewer/bootstrap.bundle.min.js').then(() => {
          System.import('assets/js/viewer/viewer.css').then(() => {
            this.showBigImg(type)
          })
        })
      })
    } else {
      this.showBigImg(type)
    }
  }
  showBigImg(type) {
    var that = this
    var imgList
    if (type == 'Modal2') {
      imgList = $('.imagesInfo')[0]
      this.viewer2 = new Viewer(imgList, {
        url: 'src',
        title: function (image) {
          return image.alt + ' (' + (this.index + 1) + '/' + this.length + ')'
        }
      })
      that.isViewer2 = true
    }
  }

  // 关闭查看图片
  closeImgModal1(modal) {
    modal.hide()
    this.picUrl = ''
  }

  //初始化search中的 项目名称
  initCompantSelect() {
    var that = this
    that.jsonApiService
      .http_obj('CorporAccount/list.html', {
        data: JSON.stringify({
          searchKey: ''
        })
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].companyId,
              text: apiList[i].companyName
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#companySelect', e => {
          that.companyId = e.id
          this.concatCompanyParam.companyId = e.id
          that.accountId = ''
          that.accountName = ''
          that.factoryId = ''
          that.factoryName = ''
          that.carNumber = ''
          that.initAcountSelect(e.text)
          that.initFactorySelect(e.id)
          that.initCarSelect(e.id)
        })
      })
  }

  del_companySelect() {
    var str = $("<span class='select2-selection__placeholder'>请选择</span>")
    $('#companySelect').val('')
    this.companyName = ''
    this.companyId = ''
    $('#select2-companySelect-container').empty()
    $('#select2-companySelect-container').attr('title', '')
    $('#select2-companySelect-container').prepend(str)
  }

  //初始化search中的 项目名称
  initCompantSelect2() {
    var that = this
    that.jsonApiService
      .http_obj('CorporAccount/list.html', {
        data: JSON.stringify({
          searchKey: ''
        })
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].companyId,
              text: apiList[i].companyName
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#companySelect2', e => {
          this.opeartionParam.companyId = e.id
          this.opeartionParam.companyName = e.text
          this.getSelectedCarList(e.id, that.opeartionParam.costType)
          this.initWaterOrderSelected(e.id, this.opeartionParam.accountingDate)
          this.opeartionParam = Object.assign(this.opeartionParam, {
            carArray: [], // 去要结算的车辆列表
            financialId: '', // 资金明细id
            costPrice: 0 // 账单总金额
          })
        })
      })
  }

  del_companySelect2() {
    var str = $("<span class='select2-selection__placeholder'>请选择</span>")
    $('#companySelect2').val('')
    this.opeartionParam.companyName = ''
    this.opeartionParam.companyId = ''
    $('#select2-companySelect2-container').empty()
    $('#select2-companySelect2-container').attr('title', '')
    $('#select2-companySelect2-container').prepend(str)
  }

  //初始化search中的 项目名称
  initFactorySelect(companyId) {
    var that = this
    that.jsonApiService
      .http_obj('CorporAccount/getAccountFactoryByCompanyId.html', {
        companyId
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].factoryId,
              text: apiList[i].factoryName
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#factorySelected', e => {
          that.factoryId = e.id
          that.initAcountSelect(e.text)
        })
      })
  }

  del_factorySelect() {
    var str = $("<span class='select2-selection__placeholder'>请选择</span>")
    $('#factorySelected').val('')
    this.factoryId = ''
    this.factoryName = ''
    $('#select2-factorySelected-container').empty()
    $('#select2-factorySelected-container').attr('title', '')
    $('#select2-factorySelected-container').prepend(str)
  }

  //初始化search中的 车辆名称
  initCarSelect(companyId) {
    var that = this
    that.jsonApiService
      .http_obj('car/queryListByCompanyId.html', {
        // companyId: "59bd13a96c8da407601b5e96",
        companyId,
        queryChildFlag: true
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].deviceId,
              text: apiList[i].carNumber
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#carSelect', e => {
          that.carNumber = e.text
        })
      })
  }

  //车辆清空
  del_carSelect() {
    var str = $("<span class='select2-selection__placeholder'>请选择</span>")
    $('#carSelect').val('')
    this.carNumber = ''
    $('#select2-carNumberSelect-container').empty()
    $('#select2-carNumberSelect-container').attr('title', '')
    $('#select2-carNumberSelect-container').prepend(str)
  }

  //search 初始化 账户名称
  initAcountSelect(companyName) {
    var that = this
    that.jsonApiService
      .http_obj('CorporAccount/list.html', {
        data: JSON.stringify({
          companyName
        })
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].id,
              text: apiList[i].accountName
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#accountSelect', e => {
          that.accountId = e.id
          that.accountName = e.id
          // that.initCarAllApi(data.id);
        })
      })
  }

  // 删除账户名称
  del_accountSelect() {
    var str = $("<span class='select2-selection__placeholder'>请选择</span>")
    $('#accountSelect').val('')
    this.accountId = ''
    this.accountName = ''
    $('#select2-accountSelect-container').empty()
    $('#select2-accountSelect-container').attr('title', '')
    $('#select2-accountSelect-container').prepend(str)
  }

  // 流水单号 新增或编辑
  initWaterOrderSelected(companyId, date) {
    if (!date) {
      const year = new Date().getFullYear()
      let month = new Date().getMonth() + 1
      let day = new Date().getDate()
      date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
    }
    var that = this
    that.jsonApiService
      .http_obj('CorporateFinancialDetails/selectSerialnumberList.html', {
        data: JSON.stringify({
          companyId,
          date
        })
      })
      .subscribe(data => {
        if (data.success) {
          var apiList = data.data
          var selectdata = []
          for (var i = 0; i < apiList.length; i++) {
            var obj = {
              id: apiList[i].id,
              text: apiList[i].serialnumber,
              arrivalAmount: apiList[i].arrivalAmount
            }
            selectdata[i] = obj
          }
        }
        this.initSelected(selectdata, '#waterOrderSelect', e => {
          that.opeartionParam.financialId = e.id
          that.opeartionParam.arrivalAmount = e.arrivalAmount
        })
      })
  }

  // 页面跳转
  jumpPage(Url, row) {
    let BaseURL = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port
    common.setCookie('jumpTo' + Url, JSON.stringify(row))
    window.open(BaseURL + '#' + Url)
  }

  paginate(e) {
    this.nowPage = e.page + 1
    this.pageSize = e.rows
    this.load()
  }
}
